package com.jl.card.parse.part.simpleTLV;

public class ProactiveCommand {

	private static final String SEP = "|";

	public static String getCommandName(byte cmd) {
		switch (cmd) {
		case 0x01:
			return "REFRESH";
		case 0x02:
			return "MORE TIME";
		case 0x03:
			return "POLL INTERVAL";
		case 0x04:
			return "POLLING OFF";
		case 0x05:
			return "SET UP EVENT LIST";
		case 0x10:
			return "SET UP CALL";
		case 0x11:
			return "Reserved for GSM/3G (SEND SS)";
		case 0x12:
			return "Reserved for GSM/3G (SEND USSD)";
		case 0x13:
			return "SEND SHORT MESSAGE";
		case 0x14:
			return "SEND DTMF";
		case 0x15:
			return "LAUNCH BROWSER";
		case 0x16:
			return "Reserved for 3GPP (GEOGRAPHICAL LOCATION REQUEST)";
		case 0x20:
			return "PLAY TONE";
		case 0x21:
			return "DISPLAY TEXT";
		case 0x22:
			return "GET INKEY";
		case 0x23:
			return "GET INPUT";
		case 0x24:
			return "SELECT ITEM";
		case 0x25:
			return "SET UP MENU";
		case 0x26:
			return "PROVIDE LOCAL INFORMATION";
		case 0x27:
			return "TIMER MANAGEMENT";
		case 0x28:
			return "SET UP IDLE MODE TEXT";
		case 0x30:
			return "PERFORM CARD APDU";
		case 0x31:
			return "POWER ON CARD";
		case 0x32:
			return "POWER OFF CARD";
		case 0x33:
			return "GET READER STATUS";
		case 0x34:
			return "RUN AT COMMAND";
		case 0x35:
			return "LANGUAGE NOTIFICATION";
		case 0x40:
			return "OPEN CHANNEL";
		case 0x41:
			return "CLOSE CHANNEL";
		case 0x42:
			return "RECEIVE DATA";
		case 0x43:
			return "SEND DATA";
		case 0x44:
			return "GET CHANNEL STATUS";
		case 0x45:
			return "SERVICE SEARCH";
		case 0x46:
			return "GET SERVICE INFORMATION";
		case 0x47:
			return "DECLARE SERVICE";
		case 0x50:
			return "SET FRAMES";
		case 0x51:
			return "GET FRAMES STATUS";
		case 0x60:
			return "(RETRIEVE MULTIMEDIA MESSAGE)";
		case 0x61:
			return "(SUBMIT MULTIMEDIA MESSAGE)";
		case 0x62:
			return "DISPLAY MULTIMEDIA MESSAGE";
		case 0x70:
			return "ACTIVATE";
		case (byte) 0x81:
			return "End of the proactive session";
		default:
			return "Reserved for proprietary use";
		}
	}

	public static String getCommandQualifier(byte cmd, byte qualifer) {
		StringBuilder sb = new StringBuilder();
		switch (cmd) {
		case 0x01:
			switch (qualifer) {
			case 0x00:
				sb.append("NAA Initialization and Full File Change Notification");
				break;
			case 0x01:
				sb.append("File Change Notification");
				break;
			case 0x02:
				sb.append("NAA Initialization and File Change Notification");
				break;
			case 0x03:
				sb.append("NAA Initialization");
				break;
			case 0x04:
				sb.append("UICC Reset");
				break;
			case 0x05:
				sb.append("NAA Application Reset, only applicable for a 3G platform");
				break;
			case 0x06:
				sb.append("NAA Session Reset, only applicable for a 3G platform");
				break;
			case 0x07:
				sb.append("Reserved by 3GPP (\"Steering of Roaming\" REFRESH support)");
				break;
			case 0x08:
				sb.append("Reserved by 3GPP (Steering of Roaming for I-WLAN)");
				break;
			default:
				sb.append("reserved values");
				break;
			}
			break;
			//return "REFRESH";
		case 0x02:
			sb.append("RFU");
			break;
			//return "MORE TIME";
		case 0x03:
			sb.append("RFU");
			break;
			//return "POLL INTERVAL";
		case 0x04:
			sb.append("RFU");
			break;
			//return "POLLING OFF";
		case 0x05:
			sb.append("RFU");
			break;
			//return "SET UP EVENT LIST";
		case 0x10:
			switch (qualifer) {
			case 0x00:
				sb.append("only if not currently busy on another call");
				break;
			case 0x01:
				sb.append("only if not currently busy on another call, with redial");
				break;
			case 0x02:
				sb.append("putting all other calls (if any) on hold");
				break;
			case 0x03:
				sb.append("putting all other calls (if any) on hold, with redial");
				break;
			case 0x04:
				sb.append("disconnecting all other calls (if any)");
				break;
			case 0x05:
				sb.append("disconnecting all other calls (if any), with redial");
				break;
			default:
				sb.append("reserved values");
				break;
			}
			break;
			//return "SET UP CALL";
		case 0x11:
			break;
			//return "Reserved for GSM/3G (SEND SS)";
		case 0x12:
			break;
			//return "Reserved for GSM/3G (SEND USSD)";
		case 0x13:
			if((qualifer & 0x01) == 0x00){
				sb.append("packing not required");
			}else{
				sb.append("SMS packing by the ME required");
			}
			break;
			//return "SEND SHORT MESSAGE";
		case 0x14:
			sb.append("RFU");
			break;
			//return "SEND DTMF";
		case 0x15:
			switch (qualifer) {
			case 0x00:
				sb.append("launch browser if not already launched");
				break;
			case 0x01:
				sb.append("not used");
				break;
			case 0x02:
				sb.append("use the existing browser (the browser shall not use the active existing secured session)");
				break;
			case 0x03:
				sb.append("close the existing browser session and launch new browser session");
				break;
			case 0x04:
				sb.append("not used");
				break;
			default:
				sb.append("reserved values");
				break;
			}
			break;
			//return "LAUNCH BROWSER";
		case 0x16:
			break;
			//return "Reserved for 3GPP (GEOGRAPHICAL LOCATION REQUEST)";
		case 0x20:
			if((qualifer & 0x01) == 0x00){
				sb.append("use of vibrate alert is up to the terminal");
			}else{
				sb.append("vibrate alert, if available, with the tone");
			}
			break;
			//return "PLAY TONE";
		case 0x21:
			if((qualifer & 0x01) == 0x00){
				sb.append("normal priority");
			}else{
				sb.append("high priority");
			}
			sb.append(SEP);
			if((qualifer & 0x80) == 0x00){
				sb.append("clear message after a delay");
			}else{
				sb.append("wait for user to clear message");
			}
			break;
			//return "DISPLAY TEXT";
		case 0x22:
			//return "GET INKEY";
		case 0x23:
			if((qualifer & 0x01) == 0x00){
				sb.append("digits (0 to 9, *, #, and +) only");
			}else{
				sb.append("alphabet set");
			}
			sb.append(SEP);
			if((qualifer & 0x02) == 0x00){
				sb.append("SMS default alphabet");
			}else{
				sb.append("UCS2 alphabet");
			}
			sb.append(SEP);
			if((qualifer & 0x04) == 0x00){
				sb.append("terminal may echo user input on the display");
			}else{
				sb.append("user input shall not be revealed in any way");
			}
			sb.append(SEP);
			if((qualifer & 0x08) == 0x00){
				sb.append("user input to be in unpacked format");
			}else{
				sb.append("user input to be in SMS packed format");
			}
			sb.append(SEP);
			if((qualifer & 0x80) == 0x00){
				sb.append("no help information available");
			}else{
				sb.append("help information available");
			}
			break;
			//return "GET INPUT";
		case 0x24:
			if((qualifer & 0x01) == 0x00){
				sb.append("presentation type is not specified");
			}else{
				sb.append("presentation type is specified in bit 2");
			}
			sb.append(SEP);
			if((qualifer & 0x02) == 0x00){
				sb.append("presentation as a choice of data values if bit 1 = '1'");
			}else{
				sb.append("presentation as a choice of navigation options if bit 1 is '1'");
			}
			sb.append(SEP);
			if((qualifer & 0x04) == 0x00){
				sb.append("no selection preference");
			}else{
				sb.append("election using soft key preferred");
			}
			sb.append(SEP);
			if((qualifer & 0x80) == 0x00){
				sb.append("no help information available");
			}else{
				sb.append("help information available");
			}
			break;
			//return "SELECT ITEM";
		case 0x25:
			if((qualifer & 0x01) == 0x00){
				sb.append("no selection preference");
			}else{
				sb.append("selection using soft key preferred");
			}
			sb.append(SEP);
			if((qualifer & 0x80) == 0x00){
				sb.append("no help information available");
			}else{
				sb.append("help information available");
			}
			break;
			//return "SET UP MENU";
		case 0x26:
			switch (qualifer) {
			case 0x00:
				sb.append("Location Information according to current NAA");
				break;
			case 0x01:
				sb.append("IMEI of the terminal");
				break;
			case 0x02:
				sb.append("Network Measurement results according to current NAA");
				break;
			case 0x03:
				sb.append("Date, time and time zone");
				break;
			case 0x04:
				sb.append("Language setting");
				break;
			case 0x05:
				sb.append("Reserved for GSM");
				break;
			case 0x06:
				sb.append("Access Technology (single access technology)");
				break;
			case 0x07:
				sb.append("ESN of the terminal");
				break;
			case 0x08:
				sb.append("IMEISV of the terminal");
				break;
			case 0x09:
				sb.append("Search Mode");
				break;
			case 0x0A:
				sb.append("Charge State of the Battery");
				break;
			case 0x0B:
				sb.append("MEID of the terminal");
				break;
			case 0x0C:
				sb.append("reserved for 3GPP (current WSID)");
				break;
			case 0x0D:
				sb.append("Broadcast Network information according tocurrent Broadcast Network Technology used");
				break;
			case 0x0E:
				sb.append("Multiple Access Technologies");
				break;
			case 0x0F:
				sb.append("Location Information for multiple access technologies");
				break;
			case 0x10:
				sb.append("Network Measurement results for multiple access technologies");
				break;
			default:
				sb.append("reserved values");
				break;
			}
			break;
			//return "PROVIDE LOCAL INFORMATION";
		case 0x27:
			switch (qualifer & 0b0000_0011) {
			case 0b0000:
				sb.append("start");
				break;
			case 0b0001:
				sb.append("deactivate");
				break;
			case 0b0010:
				sb.append("get current value");
				break;
			case 0b0011:
				sb.append("RFU");
				break;
			default:
				break;
			}
			break;
			//return "TIMER MANAGEMENT";
		case 0x28:
			sb.append("RFU");
			break;
			//return "SET UP IDLE MODE TEXT";
		case 0x30:
			sb.append("RFU");
			break;
			//return "PERFORM CARD APDU";
		case 0x31:
			sb.append("RFU");
			break;
			//return "POWER ON CARD";
		case 0x32:
			sb.append("RFU");
			break;
			//return "POWER OFF CARD";
		case 0x33:
			switch (qualifer) {
			case 0x00:
				sb.append("Card reader status");
				break;
			case 0x02:
				sb.append("Card reader identifier");
				break;
			default:
				sb.append("reserved values");
				break;
			}
			break;
			//return "GET READER STATUS";
		case 0x34:
			sb.append("RFU");
			break;
			//return "RUN AT COMMAND";
		case 0x35:
			switch (qualifer & 0b0000_0001) {
			case 0b0000:
				sb.append("non-specific language notification");
				break;
			case 0b0001:
				sb.append("specific language notification");
				break;
			}
			break;
			//return "LANGUAGE NOTIFICATION";
		case 0x40:
			sb.append("CS<");
			if((qualifer & 0x01) == 0x00){
				sb.append("on demand link establishment");
			}else{
				sb.append("immediate link establishment");
			}
			sb.append(SEP);
			if((qualifer & 0x02) == 0x00){
				sb.append("no automatic reconnection");
			}else{
				sb.append("automatic reconnection");
			}
			sb.append(SEP);
			if((qualifer & 0x04) == 0x00){
				sb.append("no background mode");
			}else{
				sb.append("immediate link establishment in background mode (bit 1 is ignored)");
			}
			sb.append(">");
			sb.append("UICC<");
			sb.append("RFU");
			sb.append(">");
			break;
			//return "OPEN CHANNEL";
		case 0x41:
			sb.append("UICC<");
			if((qualifer & 0x01) == 0x00){
				sb.append("close the TCP connection and go to \"TCP in CLOSED state\"");
			}else{
				sb.append("close the TCP connection and go to \"TCP in LISTEN state\"");
			}
			sb.append(">");
			sb.append("CS<");
			sb.append("RFU");
			sb.append(">");
			break;
			//return "CLOSE CHANNEL";
		case 0x42:
			sb.append("RFU");
			break;
			//return "RECEIVE DATA";
		case 0x43:
			if((qualifer & 0x01) == 0x00){
				sb.append("store data in Tx buffer");
			}else{
				sb.append("send data immediately");
			}
			break;
			//return "SEND DATA";
		case 0x44:
			sb.append("RFU");
			break;
			//return "GET CHANNEL STATUS";
		case 0x45:
			sb.append("RFU");
			break;
			//return "SERVICE SEARCH";
		case 0x46:
			sb.append("RFU");
			break;
			//return "GET SERVICE INFORMATION";
		case 0x47:
			if((qualifer & 0x01) == 0x00){
				sb.append("add a new service to the terminal service database");
			}else{
				sb.append("delete a service from the terminal service database");
			}
			break;
			//return "DECLARE SERVICE";
		case 0x50:
			switch (qualifer) {
			case 0x00:
				sb.append("This value tells the terminal to draw a separator between every adjoining frame");
				break;
			case 0x01:
				sb.append("This value tells the terminal not to draw a separator between every adjoining frame");
				break;
			default:
				sb.append("reserved values");
				break;
			}
			break;
			//return "SET FRAMES";
		case 0x51:
			sb.append("RFU");
			break;
			//return "GET FRAMES STATUS";
		case 0x60:
			break;
			//return "(RETRIEVE MULTIMEDIA MESSAGE)";
		case 0x61:
			break;
			//return "(SUBMIT MULTIMEDIA MESSAGE)";
		case 0x62:
			if((qualifer & 0x01) == 0x00){
				sb.append("normal priority");
			}else{
				sb.append("high priority");
			}
			sb.append(SEP);
			if((qualifer & 0x80) == 0x00){
				sb.append("clear message after a delay");
			}else{
				sb.append("wait for user to clear message");
			}
			break;
			//return "DISPLAY MULTIMEDIA MESSAGE";
		case 0x70:
			sb.append("RFU");
			break;
			//return "ACTIVATE";
		case (byte) 0x81:
			break;
			//return "End of the proactive session";
		default:
			sb.append("NOT IMPLEMENTS");
			break;
		}
		return sb.toString();
	}
}
